<?php #20070418 http://www.framework.altervista.org/FrameWork/applications/_block_editor.inc
define('BLOCKEDITOR','1.00');
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License:
 * 		http://www.opensource.org/licenses/lgpl-license.php
 *
 * For further information visit:
 * 		http://www.fckeditor.net/
 *
 * "Support Open Source software. What about a donation today?"
 *
 * File Name: sample01.php
 * 	Sample page.
 *
 * File Authors:
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
 */


// carica libemoticons e libBBcode se sono presenti
//if (file_exists("extras/bbcode/libBBcode.inc")&& !defined('LIBBBCODE'))
//    include "extras/bbcode/libBBcode.inc";
//if (file_exists("extras/emoticons/libEmoticons.inc")&& !defined('LIBEMOTICONS') )
//    include "extras/emoticons/libEmoticons.inc";
loadlib("libBBcode");
loadlib("libEmoticons");




$file=$_GET['file'];
$appdest=$_GET['appdest'];
$prpath=$_GET['prpath'];
$pic_path = substr($file,0,-7)."/images";
//echo "$pic_path<br/>";

?>

<?php structure_openBlock("table appl","FrameWork editor",""); ?>
  <p>
    File:<b>[</b><?=$file?><b>]</b>
    <hr />
		<form name='edit' action="index.php?appname=<?=$appdest?>" method="post">

    <input type='hidden' name='save' value='<?=$file?>'>
    <input type='hidden' name='prpath' value='<?=$prpath?>'>
<?php

if (file_exists("extras/FCKeditor/fckeditor.php")){
  include("extras/FCKeditor/fckeditor.php");

  $sBasePath ="extras/FCKeditor/" ;

  $oFCKeditor = new FCKeditor('editor') ;
  $oFCKeditor->BasePath	= $sBasePath;
  $oFCKeditor->Height= 400;
  $oFCKeditor->Value	= @join(@file($file));
  $oFCKeditor->Create() ;
}
else{
    if (defined('LIBBBCODE'))creatoolbar("document.edit.editor");
?>
  <textarea name='editor' style="width:100%;height:300px;" >
<?php
  $datas=@join(@file($file));
  if (defined('LIBEMOTICONS'))$datas=html2emoticons($datas);
  if (defined('LIBBBCODE'))$datas=html2bb($datas);
    echo $datas;
?>
  </textarea>
<?php } ?>
      <hr />
	<input type="submit" value="Save">
    </form>




<?php if ((defined('LIBGROUP') && group_getusergroup("webmaster",user_getuser())) || admin_isadmin()){
	$op=$_GET['op'];
	if ($op=="upload"){
	    if (move_uploaded_file($_FILES['image']['tmp_name'], $pic_path."/".$_FILES['image']['name'])) {
		//echo $_FILES['image']['name'];
		if (strtolower(substr($_FILES['image']['name'],-4))==".php" )
		    unlink($pic_path."/".$_FILES['image']['name']);
		else{
		    echo "<script>alert('immagine ".$_FILES['image']['name']." caricata');</script>";
		}
	    }
	}
	if ($op=="delimage"){
	    $image=$_POST['image'];
	    if (file_exists($pic_path."/".$image)){
		unlink($pic_path."/".$image);
		echo "<script>alert('immagine $image eliminata');</script>";
	    }
	}
?>

    <hr />
    <form name="images_upload" action="index.php?appname=<?=$appname?>&appdest=<?=$appdest?>&file=<?=$file?>&op=upload" enctype='multipart/form-data' method='post'>
    carica un immagine<input type="file" name="image"><input type=submit value="load">
    </form>

    <form name="images" action="index.php?appname=<?=$appname?>&appdest=<?=$appdest?>&file=<?=$file?>&op=delimage" enctype='multipart/form-data' method='POST'>
    <select name="image">

    <?php
	//library auto load
	$i=0;
	$fd=opendir("$pic_path");
	while (false !== ($nf= readdir($fd))){
	    if ($nf[0]!='.' )
		$images[$i++]=$nf;
	}
	closedir($fd);
	if ($i>0){
	    sort($images);
	    foreach($images as $image){
		echo"<option>$image</option>";
	    }
	}
    ?>

    </select>

<?php if (file_exists("extras/FCKeditor/fckeditor.php")){?>

    <input type='button' name='insert' value='inserisci' onclick="
    var oEditor = FCKeditorAPI.GetInstance('editor') ;
    var index= images.image.selectedIndex;
    if (index==-1)index=0;
    var name = document.images.image.options[index].text;
    var html= '<img src=\'<?php echo base_path()."$pic_path/";?>'+name+'\'/>\n';
    if (name) {
	    oEditor.InsertHtml(html);
    }
    " />
<?php }else{ ?>
    <input type='button' name='insert' value='inserisci' onclick="
    var oEditor = document.edit.editor;
    var index= images.image.selectedIndex;
    if (index==-1)index=0;
    var name = document.images.image.options[index].text;
    var html= '<img src=\'<?php echo base_path()."$pic_path/";?>'+name+'\'/>\n';
    //alert(html);
    if (name) {
	var before = oEditor.value.substring(0, oEditor.selectionStart);
	var sel    = oEditor.value.substring(oEditor.selectionStart, oEditor.selectionEnd);
	var after  = oEditor.value.substring(oEditor.selectionEnd, oEditor.textLength);
	oEditor.value = before + html + after;
    }
    " />
<?php } ?>
    <input type='submit' name='delete' value='elimina' />
    <hr />
    </form>
<?php } ?>
</p>
<?php structure_closeBlock(); ?>

